package com.ygqh.baby.controller.mobile;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.po.YgUserIdentity;
import com.ygqh.baby.service.YgUserIdentityService;
import com.ygqh.baby.utils.SessionUtil;

@Controller()
@RequestMapping("/mobile/identity")
public class YgUserIdentityController extends BaseController {
	protected Logger logger = Logger.getLogger(this.getClass());

	@Autowired
	private YgUserIdentityService ygUserIdentityService;

	@RequestMapping(value = "/auth")
	@ResponseBody
	public JSONPObject auth(String idNo, String name, String callback) {
		// idNo =Base64.encodeBase64String( Base64.decodeBase64(idNo));
		// name =Base64.encodeBase64String( Base64.decodeBase64(name));

		Long userId = SessionUtil.getCurrentUser().getId();
		Message auth = ygUserIdentityService.auth(userId, idNo, name);
		return new JSONPObject(callback, auth);
	}

	@RequestMapping(value = "/findIdentity")
	@ResponseBody
	public JSONPObject findIdentity(String idNo, String name, String callback) {
		Long userId = SessionUtil.getCurrentUser().getId();
		YgUserIdentity identity = ygUserIdentityService.findByUserId(userId);
		identity.setIdNo(YgUserIdentity.idNoAddStar(identity.getIdNo()));
		return new JSONPObject(callback, identity);
	}

	@RequestMapping(value = "/certified")
	@ResponseBody
	public JSONPObject isAuth(String idNo, String name, String callback) {
		Long userId = SessionUtil.getCurrentUser().getId();
		boolean certified = ygUserIdentityService.certified(userId);
		return new JSONPObject(callback, certified);
	}

}
